from selenium.webdriver.common.by import By
from selenium import webdriver
import time
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait


driver=webdriver.Edge()
# 获取地址
driver.get('http://10.59.9.12:7001/')
# 强制等待
time.sleep(3)
# 点击登录
driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
# 输入用户名
driver.find_element(By.NAME,'username').send_keys('13012558376')
# 输入密码
driver.find_element(By.NAME,'password').send_keys('123456Aa')
# 显示等待
driver.implicitly_wait(10)
# 点击登录按钮
driver.find_element(By.CLASS_NAME,'finish-btn').click()
# 点击首页
driver.find_element(By.LINK_TEXT,'首页').click()
# 搜索商品
a=driver.find_element(By.CLASS_NAME,'search-input')
a.send_keys('宋牌')
# 显示等待
WebDriverWait(driver,20,0.5).until(EC.presence_of_element_located((By.CLASS_NAME,'search-input-btn'))).click()
print(a.size)
# 点击商品详情
driver.find_element(By.XPATH,'//img[@src="/uploads/images/20250620/67e1bd127f10d17039e45464df4c460a.jpg"]').click()
# 更改数量
b=driver.find_element(By.ID,'store_nums')
b.clear()
b.send_keys('3')
# 加入购物车
driver.find_element(By.ID,'add-cart').click()

# 9.合理使用上传或下载，若无上传、下载功能请给出思路
driver.find_element(By.NAME,'password').send_keys(r'文件路径')
